﻿@{
    ViewBag.Title = "updaUserInfo";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}

<script src="/Content/After/js/jquery.min.js"></script>
<script>
    function cancelUserInfo() {
        location.href = "/UserInfo/Index";
    }
    function updaUserInfodo(UserId) {

        var AuthorId = new Array;
        $("[name='CkOne']:checked").each(function () {
            AuthorId.push($(this).val());
        })


        var UserPwd = $("#UserPwd").val();
        var UserChineseName = $("#UserChineseName").val();
        var UserSex = $("[name='sex']:checked").val();
        var UserPhone = $("#UserPhone").val();
        var UserEmail = $("#UserEmail").val();
        var DepartId = $("#DepartId").val();
        var UserSecrecy = $("[name='Secrecy']:checked").val();
        var UserState = $("[checked='checked']:checked").val();

        $.ajax({
            type: 'POST',
            url: '/UserInfo/FnupdaUserInfodo',
            data: {
                UserId: UserId,
                UserPwd: UserPwd, UserChineseName: UserChineseName,
                UserSex: UserSex, UserPhone: UserPhone,
                UserEmail: UserEmail, DepartId: DepartId, AuthorId: AuthorId.toString(),
                UserSecrecy: UserSecrecy, UserState: UserState
            },
            dataType: 'Json',
            success: function (mes) {
                if (mes > 0) {
                    alert("修改成功！");
                    location.href = "/UserInfo/Index";
                }
                else {
                    alert("保存失败！");

                }
            }
        })
    }
</script>

@using ZX.HIS.Model;
@{
    List<ZX.HIS.Model.AuthorInfo> list = ViewBag.AuthorId;

    ZX.HIS.Model.UserInfo UserInfo = ViewBag.UserInfo;
    int UserId = ViewBag.UserId;

    List<ZX.HIS.Model.AuthorUserInfo> AuthorUserInfo = ViewBag.AuthorUserInfo;
}
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>挂号信息</strong> </div>
<div style="width:100%">
    <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3><a href="/UserInfo/Index" class="actionBtn">返回</a>用户修改</h3>
        <div style="width:50%;float:left">
            <table width="100%" border="0" class="table table-bordered  tableBasic">
                <tbody>
                    <tr>
                        <td>密码:</td>
                        <td><input id="UserPwd" type="text" class="inpMain" size="40" value="@UserInfo.UserPwd" /></td>
                    </tr>
                    <tr>
                        <td>中文名:</td>
                        <td><input id="UserChineseName" type="text" class="inpMain" size="40" value="@UserInfo.UserChineseName" /></td>
                    </tr>
                    <tr>
                        <td>性别:</td>

                        @if (UserInfo.UserSex == 1)
                        {
                            <td>
                                <input id="UserSex" type="radio" value="1" name="sex" checked="checked" />
                                <span>男</span>
                                <input id="UserSex" type="radio" value="0" name="sex" />
                                <span>女</span>
                            </td>
                        }
                        else
                        {
                            <td>
                                <input id="UserSex" type="radio" value="1" name="sex" />
                                <span>男</span>
                                <input id="UserSex" type="radio" value="0" name="sex" checked="checked" />
                                <span>女</span>
                            </td>
                        }

                    </tr>

                    <tr>
                        <td>手机号:</td>
                        <td><input id="UserPhone" type="text" class="inpMain" size="40" value="@UserInfo.UserPhone" /></td>
                    </tr>
                    <tr>
                        <td>邮箱:</td>
                        <td><input id="UserEmail" type="email" class="inpMain" size="40" value="@UserInfo.UserEmail" /></td>
                    </tr>
                    <tr>
                        <td>科室:</td>
                        <td>@Html.DropDownList("DepartId")</td>
                    </tr>

                    <tr>
                        <td>保密设置:</td>
                        @if (UserInfo.UserSecrecy == 0)
                        {
                            <td>
                                查看诊所全部患者及处方信息：
                                <input id="UserSecrecy" type="radio" value="1" name="Secrecy" />是
                                <input id="UserSecrecy" type="radio" value="0" name="Secrecy" checked="checked" />否
                            </td>
                        }
                        else
                        {
                            <td>
                                查看诊所全部患者及处方信息：
                                <input id="UserSecrecy" type="radio" value="1" name="Secrecy" checked="checked" />是
                                <input id="UserSecrecy" type="radio" value="0" name="Secrecy" />否
                            </td>
                        }
                    </tr>
                    <tr>
                        <td>状态:</td>
                        @if (UserInfo.UserState == 1)
                        {
                            <td>
                                <input id="UserState" type="radio" value="1" name="state" checked="checked" />启用
                                <input id="UserState" type="radio" value="0" name="state" />禁用
                            </td>
                        }
                        else
                        {
                            <td>
                                <input id="UserState" type="radio" value="1" name="state" />启用
                                <input id="UserState" type="radio" value="0" name="state" checked="checked" />禁用
                            </td>
                        }
                    </tr>
                    <tr></tr>
                    <tr>
                        <td></td>
                        <td>
                            <input id="Button1" type="button" class="btn" value="修改" onclick="updaUserInfodo(@UserId)" />
                            <input id="Button1" type="button" class="btn" value="取消" onclick="cancelUserInfo()" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div style="width:40%;float:right">
            <input id="CkAll" type="checkbox" name="CkAll" />全选
            <ul>
                @foreach (var i in list)
                {
                    if (i.AuthorParentId == 0)
                    {
                        if (AuthorUserInfo.Where(p => p.AuthorId == i.AuthorId).Count() > 0)
                        {
                            <li class="list-group-item ">
                                <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                <input type="checkbox" checked="checked" ckparent="@i.AuthorId" name="CkOne" ckchild="@i.AuthorParentId" value="@i.AuthorId" onchange="ChangeCheck(@i.AuthorParentId,@i.AuthorId,this.checked)" />
                                @i.AuthorName
                                <ul class="hide">
                                    @foreach (var p in list)
                                    {
                                        if (p.AuthorParentId == i.AuthorId)
                                        {
                                            if (AuthorUserInfo.Where(d => d.AuthorId == p.AuthorId).Count() > 0)
                                            {

                                                <li class="list-group-item ">
                                                    <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                                    <input type="checkbox" checked="checked" ckparent="@p.AuthorId"   name="CkOne" ckchild="@p.AuthorParentId" value="@p.AuthorId" onchange="ChangeCheck(@p.AuthorParentId,@p.AuthorId,this.checked)" />
                                                    @p.AuthorName
                                                </li>
                                            }
                                            else
                                            {
                                                <li class="list-group-item ">
                                                    <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                                    <input type="checkbox" ckparent="@p.AuthorId" name="CkOne" ckchild="@p.AuthorParentId" value="@p.AuthorId" onchange="ChangeCheck(@p.AuthorParentId,@p.AuthorId,this.checked)" />
                                                    @p.AuthorName
                                                </li>
                                            }
                                        }
                                    }
                                </ul>
                            </li>
                        }
                        else
                        {
                            <li class="list-group-item ">
                                <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                <input type="checkbox" ckparent="@i.AuthorId" name="CkOne" ckchild="@i.AuthorParentId" value="@i.AuthorId" onchange="ChangeCheck(@i.AuthorParentId,@i.AuthorId,this.checked)" />
                                @i.AuthorName
                                <ul class="hide">
                                    @foreach (var p in list)
                                    {
                                        if (p.AuthorParentId == i.AuthorId)
                                        {
                                            if (AuthorUserInfo.Where(d => d.AuthorId == p.AuthorId).Count() > 0)
                                            {

                                                <li class="list-group-item ">
                                                    <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                                    <input type="checkbox" checked="checked" ckparent="@p.AuthorId" name="CkOne" ckchild="@p.AuthorParentId" value="@p.AuthorId" onchange="ChangeCheck(@p.AuthorParentId,@p.AuthorId,this.checked)" />
                                                    @p.AuthorName
                                                </li>
                                            }
                                            else
                                            {
                                                <li class="list-group-item ">
                                                    <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                                    <input type="checkbox" ckparent="@p.AuthorId" name="CkOne" ckchild="@p.AuthorParentId" value="@p.AuthorId" onchange="ChangeCheck(@p.AuthorParentId,@p.AuthorId,this.checked)" />
                                                    @p.AuthorName
                                                </li>
                                            }
                                        }
                                    }
                                </ul>
                            </li>
                        }
                    }
                }
            </ul>
        </div>
        <div class="clear"></div>
    </div>

    <script>
        function ChangeCheck(ParentId, ChildId, IsCheck) {
            $("[ckparent=" + ParentId + "]").prop("checked", IsCheck)
            $("[ckchild=" + ChildId + "]").prop("checked", IsCheck);
        }
        $(function () {
            $("span[name=ClickLi]").click(function () {

                var ThisUl = $(this).parent().find("ul");

                if ($(ThisUl[0]).hasClass("hide")) {
                    $(ThisUl[0]).stop().fadeIn(500).removeClass("hide");
                    $(this).removeClass("glyphicon-chevron-right").addClass("glyphicon-chevron-down")
                } else {
                    $(ThisUl[0]).addClass("hide");
                    $(this).addClass("glyphicon-chevron-right").removeClass("glyphicon-chevron-down");
                }
            })
            $("#CkAll").click(function () {
                $(":input[name=CkOne]").prop("checked", this.checked);
            })
        })
    </script>
